<template>
  <div class="review_page">
    <div class="head">
      <div   @click="$router.go(-1)"  class="iconfont icon-zuojiantou"></div>
      <div >评论</div>
    </div>
    <div class="review" v-if="remark">
      
      <div class="user"  v-for="(item,index) in remark" :key="index">
        <div class="img">
          <img
            :src="item.avatar "
            alt=""
          />
        </div>
        <div class="info">
          <div class="user_name">{{item.nickName}} <span class="level">lv.{{item.userLevel}}</span></div>
          <div class="like">
            <span class="star" v-show="item.grade"><van-rate v-model="item.grade" readonly color="#ffd21e" :size="16" /></span>
            <span class="time">{{changeTime(item.time)}}</span>
          </div>
          <div class="review_content">
           {{item.comment}}
          </div>
        </div>
        <div class="good"><span class="num">{{item.likes}}</span><span :class="['iconfont','icon-dianzan',{changePraise:item.isPraise}]" @click="praiseFun(item)"></span></div>
      </div>
     
    </div>
  </div>
</template>

<script>
import {getCommentGetComments} from "../api/base"
export default {
  data(){
    return{
      bookId:null,
      remark:null, // 评论列表
    }

    
  },
  methods:{
      changeTime(time){
        return new Date(time).toLocaleDateString();
    },
      
    // 获取书籍评论
    getCommentGetCommentsFun(){
       getCommentGetComments({bookId:this.bookId}).then(data=>{
              console.log(data.all.list);
              this.remark = data.all.list;
       })
    },

     // 点赞
    praiseFun(item){
        console.log("点赞了");
        console.log(item);
        item.isPraise = item.isPraise == 0 ? 1 : 0;
        item.likes = item.isPraise == 1 ? item.likes + 1 : item.likes - 1 
      
    }
  },

  created(){
     let info = this.$store.state.bookInfo;
     
     this.bookId = info.id;


    this.getCommentGetCommentsFun()
  }
};
</script>

<style lang="less">
.review_page {
    .head{
        position: relative;
        padding: 10px 12px;
        box-sizing: border-box;
        text-align: center;
        .icon-zuojiantou{
            position: absolute;
            top: 12px;
            left: 12px;
        }
    }
  .review {
    padding: 0 12px;
    box-sizing: border-box;
    padding-bottom: 50px;
    .user {
        position: relative;
      margin-bottom: 30px;
      display: flex;
      .img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
        margin-right: 10px;
        img {
          width: 35px;
          height: 35px;
          border-radius: 50%;
        }
      }
      .info {
        .user_name {
          margin-bottom: 5px;
          .level {
            border: 1px solid #ddd;
            font-size: 13px;
            margin-left: 4px;
            padding: 0 3px;
            border-radius: 3px;
          }
        }
        .like {
          margin-bottom: 8px;
          .star {
            margin-right: 10px;
          }
          .time {
            font-size: 14px;
          }
        }
        .review_content {
          font-size: 15px;
          color: #646464;
          line-height: 15px;
        }
      }
       .good{
          position: absolute;
          right: 0;
          top: 0;
          .num{
              margin-right: 4px;
              font-size: 14px;
          }
           .changePraise{
            color: red;
          }
      }
    }
  }
}
</style>